package com.ruitu.mall_98_2.order;

import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.beanu.arad.base.my_base.MyBaseActivity;
import com.beanu.arad.base.my_base.base_list.ListBaseAdapter;
import com.beanu.arad.widget.progressactivity.ProgressLayout;
import com.ruitu.mall_98_2.R;
import com.ruitu.router_module.A_Rutils;
import com.ruitu.router_module.AppHolder;
import com.ruitu.router_module.bean.DataAdapter;
import com.ruitu.router_module.bean.order.ConfirOrder;
import com.ruitu.router_module.bean.product.Product;

import java.util.ArrayList;
import java.util.List;

public class AdvancePayResultActivity extends MyBaseActivity {
    private RecyclerView recyclerView;
    private TextView tv_recipients;
    private TextView tv_recipients_tel;
    private TextView tv_shipping_address;
    private TextView tv_pay_result_total;
    private TextView tv_pay_status;
    private DataAdapter adapter;

    private TextView tv_end_pay;
    private String payMoney;
    private String orderId;

    private ConfirOrder confirOrders;
    private List<Integer> skipId = new ArrayList<>();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int getLayoutRes() {
        return R.layout.activity_advance_pay_result;
    }

    @Override
    protected ProgressLayout findProgressLayout() {
        return null;
    }

    @Override
    protected void initViews() {
        super.initViews();
        setHeadTitle("支付成功");
        confirOrders = (ConfirOrder) getIntent().getExtras().getSerializable("confirOrder");
        tv_recipients = findViewById(R.id.tv_recipients);
        tv_recipients_tel = findViewById(R.id.tv_recipients_tel);
        tv_shipping_address = findViewById(R.id.tv_shipping_address);
        tv_pay_result_total = findViewById(R.id.tv_pay_result_total);
        tv_pay_status = findViewById(R.id.tv_pay_status);
        tv_end_pay = findViewById(R.id.tv_end_pay);
        recyclerView = findViewById(R.id.recyclerView);
        initData();
    }

    private void initData() {
        if (TextUtils.equals(confirOrders.getIsPayOver(), "0")) {
            tv_pay_status.setText("订金支付成功");
            tv_end_pay.setText("支付尾款时间等待商家通知");
        } else {
            tv_pay_status.setText("尾款支付成功");
            tv_end_pay.setText("我们将以最快的时间为您发货~~");
        }
        tv_recipients.setText(confirOrders.getConsigneeName());
        tv_recipients_tel.setText(confirOrders.getCollectGoodsPhone());
        tv_shipping_address.setText(confirOrders.getOrderProvinceCode() + confirOrders.getOrderCityCode() + confirOrders.getOrderCountyCode() + confirOrders.getCollectGoodsAddress());
        tv_pay_result_total.setText("￥" + confirOrders.getNeedPay());

        GridLayoutManager manager = new GridLayoutManager(this, 2) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        };
        recyclerView.setLayoutManager(manager);
        adapter = new DataAdapter(this);
        recyclerView.setAdapter(adapter);
        adapter.setDataList(AppHolder.instance().getGlobalProList());

        adapter.setOnItemClickListener(new ListBaseAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View itemView, int position) {
                Product product = new Product();
                product.setGoodId(AppHolder.instance().getGlobalProList().get(position).getGoodsId());
                Bundle bundle = new Bundle();
                bundle.putSerializable("product", product);
                try {
                    A_Rutils.startActivity(AdvancePayResultActivity.this, "com.ruitu.mall_98_1.product.activity.ProductDetailActivity", bundle);
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
